using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Fated {
    public static class MapDisplayer {
        private static GraphicsDevice gD;
        private static SpriteBatch sB;
        private static SpriteFont font;

        public static void initialize(GraphicsDevice g, SpriteBatch s, SpriteFont f) {
            gD = g;
            sB = s;
            font = f;
        }
        public static void renderMap(AbstractMap map) {
            Rectangle tileSize = map.getTileSize();
            Vector2 dest = Vector2.Zero;
            int height = map.getHeight();
            int width = map.getWidth();
            Point cursor = map.getCursor();
            Point rangeCenter = map.getRangeCenter();

            for (int x = 0; x < width; ++x) {
                for (int y = 0; y < height; ++y) {
                    dest.X = tileSize.Width * x;
                    dest.Y = tileSize.Height * y;

                    Color c = Color.White;
                    if (x == cursor.X && y == cursor.Y) {
                        c = Color.LightBlue;
                    } else if (map.isRangeVisible()) {
                        if (map.distance(x, y, rangeCenter.X, rangeCenter.Y) <= map.getRangeRadius()) {
                            c = Color.MediumVioletRed;
                        }
                    }
                    if (map.containsCharacter(x, y)) {
                        sB.DrawString(font, map.getCharacter(x, y).Substring(0,1), dest, c);
                    } else {
                        sB.DrawString(font, map.getTile(x, y).ToString(), dest, c);
                    }
                }
            }

        }
    }
}
